package com.itheima.day15.work1;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class ServerDemo {
    public static void main(String[] args) throws IOException {
        DatagramSocket  ds=new DatagramSocket(10000);//接收端需要写个端口号
        byte[] bytes = new byte[1024];
        DatagramPacket  dp=new DatagramPacket(bytes,bytes.length);
        System.out.println("接收前：");
        ds.receive(dp);
        System.out.println("接收后：");
        byte[] data = dp.getData();
        int length = data.length;
        System.out.println(new String(data,0,length));
        //System.out.println(new String(bytes,0,length)); //bytes数组
        ds.close();
    }
}
